//
//  MCGoodsDetailDescribeViewController.swift
//  StoreManage
//
//  Created by MC on 2018/2/6.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCGoodsDetailDescribeViewController: MCViewController {

    var goodsId = 0
    
    private var goodsDetailArray : NSArray = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        baseSetting()
        
        initUI()
        
        sendNetworking()
    }
    
    // MARK: - System Delegate
    
    // MARK: - Custom Delegate
    
    // MARK: - Action
    
    // MARK: - Network
    func sendNetworking() {
        let para = [
            "goodsId" : goodsId
            ] as [String : Any]
        
        MCNetwork_post(url: JAVA_getGoodsPictures, para: para as [String : AnyObject], vc: self,hudSuperView: self.view,isHiddenTabbar: true, success: { (response) in
            let dataDict = response["data"] as! [String : AnyObject]
            
            
            let goodsNavigate = dataDict["goodsNavigate"] as? NSArray ?? []
            self.goodsDetailArray = dataDict["goodsDetail"] as? NSArray ?? []

            let navigateArrayM = NSMutableArray()
            
            for dict in goodsNavigate {
                let tempDict = dict as? [String:Any] ?? [:]
                navigateArrayM.add(tempDict["navigateImage"] ?? "")
            }
            
            self.topView.cycleScrollView.imageURLStringsGroup = navigateArrayM as! [Any]
            
            self.tableView.reloadData()
            
        }, dislike: { (response) in }) { (error) in }
    }
    
    // MARK: - Method
    func baseSetting() {
        self.view.backgroundColor = UIColor.white
    }
    
    func initUI() {
        view.addSubview(tableView)
        tableView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(view)
        }
        
        tableView.tableHeaderView = topView
    }
    
    // MARK: - Setter & Getter
    lazy var tableView: MCTableView = {
        let tableView = MCTableView.init(frame: CGRect.zero, style: UITableViewStyle.plain)
        tableView.delegate = self
        tableView.dataSource = self
        return tableView
    }()
    
    lazy var topView: MCGoodsDetailDescribeTopView = {
        let view = MCGoodsDetailDescribeTopView()
        view.cycleScrollView.localizationImageNamesGroup = [#imageLiteral(resourceName: "Reuse_placeholder_1_1"),#imageLiteral(resourceName: "Reuse_placeholder_1_1")]
        return view
    }()
}


extension MCGoodsDetailDescribeViewController : UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.goodsDetailArray.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return MCScreenWidth
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = UITableViewCell.init(style: UITableViewCellStyle.value1, reuseIdentifier: "cell")
        
        cell.selectionStyle = UITableViewCellSelectionStyle.none
        
        let dict = self.goodsDetailArray[indexPath.row] as? [String:Any] ?? [:]
        
        let imageView = UIImageView()
        imageView.sd_setImage(with: URL.init(string: dict["imagePath"] as! String), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
        cell.contentView.addSubview(imageView)
        imageView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(cell.contentView)
        }
        
        
        return cell
    }
}
